<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .iframeDoc{
            width: 90vw;
            height: 90vh;
            border: medium none;
        }
    </style>
</head>
<body>

    <iframe id="myframe" class="iframeDoc"
    rameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"
     src="http://localhost:3001"></iframe>
    <script>

        // idnex.html

//获取iframe元素
iFrame = document.getElementById('myframe')

//iframe加载完毕后再发送消息，否则子页面接收不到message
iFrame.onload = function(){

  //iframe加载完立即发送一条消息
  iFrame.contentWindow.postMessage('MessageFromIndex1','*');

}
// iframePage.html

//回调函数
function receiveMessageFromIndex ( event ) {
  console.log( 'receiveMessage from  xioo-docs/ ', event )
}

//监听message事件
window.addEventListener("message", receiveMessageFromIndex, false);

    </script>
</body>
</html>